//短网址，将长网址缩短服务
const path = require("path");
module.exports = class extends think.Service {
	constructor() {
		super();
		this.siteurl = 'http://huitaor.cn';
		this.appid = '90d4cd10b96911e8be10b9aa2ae5faeb';
		this.appkey = '8f253b622746026b7017277dd25f6189';

	}
	async create(url,orginUrl) {
		if(orginUrl){
			this.siteurl = orginUrl;
		}
		let res = await this.fetch(`${this.siteurl}/app/dwz/index/short?appid=${this.appid}&appkey=${this.appkey}&url=${this.siteurl}${url}`).then(res => res.json());
		console.log(res);

		if(res.errno == 0) {
			return this.siteurl +'/d/'+ res.data;
		} else {
			return this.siteurl+url;
		}

	}

	

}